package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shopping")
@Slf4j
public class ProductCateController {

    @Reference
    IProductCateService productCateService;


    @Anoymous
    @GetMapping("/categories")
    public ResponseData productCate(@RequestParam(value = "sort", required = false, defaultValue = "1")String sort) {
        log.info("request product categories!!");

        AllProductCateRequest allProductCateRequest = new AllProductCateRequest();
        allProductCateRequest.setSort(sort);


        AllProductCateResponse allProductCate
                = productCateService.getAllProductCate(allProductCateRequest);
        log.info("all the categories is " + allProductCate.getProductCateDtoList());
        if (!ShoppingRetCode.SUCCESS.getCode().equals(allProductCate.getCode())) {
            return new ResponseUtil<>().setErrorMsg(allProductCate.getMsg());
        }

        return new ResponseUtil<>().setData(allProductCate.getProductCateDtoList());

    }
}
